package com.example.wanxiang.controller;

import com.example.wanxiang.dto.GroupDto;
import com.example.wanxiang.entity.Group;
import com.example.wanxiang.repository.GroupRepository;
import com.example.wanxiang.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/group")
public class GroupController {

    @Autowired
    private GroupService groupService;

    @PostMapping("/add/{id}")
    public Group add(@RequestBody GroupDto groupDto, @PathVariable String id)
    {
        return groupService.update(id,groupDto);
    }

    @PostMapping("/create")
    public Group create(@RequestBody GroupDto groupDto)
    {
        return groupService.create(groupDto);
    }

    @PostMapping("/del/{id}")
    public Group del(@PathVariable String id){
        return groupService.delete(id);
    }

    @PostMapping("/findByGroupName/{groupName}")
    public Group findByName(@PathVariable String groupName)
    {
        return groupService.getByGroupName(groupName);
    }
}
